<template lang="html">
  <div>
    <selfHeader></selfHeader>
    <div class="car">

      <mt-field label="身份证号" placeholder="请输入身份证号" v-model="from.idNumber"></mt-field>
      <mt-field label="真实姓名" placeholder="请输入真实姓名" v-model="from.name"></mt-field>
      <mt-field label="手机号码" placeholder="请输入手机号码" v-model="from.phoneNum"></mt-field>
      <button class="btn" @click='updateAuthentication'>认证</button>
    </div>
  </div>
</template>

<script>
import {updateAuthentication} from '@/http/api'
import Baseline from '@/common/_baseline.vue'
import {Toast, Field} from 'mint-ui'
import selfHeader from '@/common/header'

export default {
  components: {
    'v-baseline': Baseline,
    Field,
    selfHeader
  },
  data() {
    return {
      from: {
        idNumber: '',
        name: '',
        phoneNum: ''
      }
    }
  },
  created() {
  },
  methods: {
    async updateAuthentication() {
      const user = JSON.parse(localStorage.getItem('UserMessage'))
      const data = {
        uid: user.user.uid,
        ...this.from
      }
      const res = await updateAuthentication(data)
      if (res.code * 1 === 200) {
        Toast('实名认证成功');
        let UserMessage = JSON.parse(localStorage.getItem('UserMessage'))
        UserMessage.user.cardId = this.from.idNumber
        localStorage.setItem('UserMessage', JSON.stringify(UserMessage))
        this.$router.push('/')
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import '../assets/fz.less';
@import '../assets/index/style.css';
@import '../assets/user/icon/carstyle.css';
.car {
  width: 100%;
  margin-top: 60px;
}
</style>

